package com.test.nnooolwdeaer.util_wooden.helper_wooden;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.text.TextUtils;

import com.test.nnooolwdeaer.util_wooden.StringUtil_wooden;
import com.test.nnooolwdeaer.activity_fragment_wooden.base_wooden.BaseApplication_wooden;

/**
 * 用户信息管理
 * 初始化本地token/mobile等数据
 */
public class UserInfoHelper_wooden {

    public static final String SP_KEY_TOKEN_wooden = "token";
    public static final String SP_KEY_MOBILE_wooden = "phoneNum";
    public static final String SP_KEY_USERID_wooden = "userid";
    public static final String SP_KEY_COUNTRY_WORD_wooden = "country_word";
    public static final String SP_KEY_COUNTRY_NAME_wooden = "country_name";

    public static final String SP_KEY_NORMALDIALOG_COUNT_wooden = "normal_dialog_count";
    public static final String SP_KEY_ACTIVEDIALOG_COUNT_wooden = "active_dialog_count";

    public static final String LOGIN_TYPE_REGISTER_wooden = "REGISTER";
    public static final String LOGIN_TYPE_OLD_wooden = "OLD";

    /**
     * 用户是否选择过额度
     */
    public static String USER_HAD_SELECTED_AMOUNT_FLAG_wooden = "NO";

    /**
     * 全局sp
     */
    private final SharedPreferences mSharedPreferences_wooden;

    /**
     * 登录手机号
     */
    private String mMobile_wooden;
    /**
     * 登录token
     */
    private String mToken_wooden;
    /**
     * 登录user_id
     */
    private String mUserId_wooden;
    /**
     * 登录接口字段
     */
    private String mCountryWord_wooden;
    /**
     * 国家名
     */
    private String mCountryName_wooden;

    /**
     * 评分弹窗配置
     */
    private int normaldialogCount;
    private int activedialogCount;


    private static class InnerUserInfoHelper_wooden {
        private static final UserInfoHelper_wooden instance_wooden = new UserInfoHelper_wooden();
    }

    public static UserInfoHelper_wooden getInstance_wooden() {
        return InnerUserInfoHelper_wooden.instance_wooden;
    }

    private UserInfoHelper_wooden() {
        mSharedPreferences_wooden = BaseApplication_wooden.getApplication().getSharedPreferences(DeviceHelper_wooden.getPackageName_wooden(), Context.MODE_PRIVATE);
        this.mMobile_wooden = mSharedPreferences_wooden.getString(SP_KEY_MOBILE_wooden, "");
        this.mToken_wooden = mSharedPreferences_wooden.getString(SP_KEY_TOKEN_wooden, "");
        this.mCountryWord_wooden = mSharedPreferences_wooden.getString(SP_KEY_COUNTRY_WORD_wooden, "");
        this.mCountryName_wooden = mSharedPreferences_wooden.getString(SP_KEY_COUNTRY_NAME_wooden, "");
        this.mUserId_wooden = mSharedPreferences_wooden.getString(SP_KEY_USERID_wooden, "");
        normaldialogCount = mSharedPreferences_wooden.getInt(SP_KEY_NORMALDIALOG_COUNT_wooden,0);
        activedialogCount = mSharedPreferences_wooden.getInt(SP_KEY_ACTIVEDIALOG_COUNT_wooden,0);
    }

    public void init_wooden(Context context) {}

    //判断是否已经登录
    public boolean didLogin_wooden() {
        return (!TextUtils.isEmpty(this.mToken_wooden)&&(!TextUtils.isEmpty(this.mCountryWord_wooden)));
    }

    public String getMobile_wooden() {
        mMobile_wooden = StringUtil_wooden.getSafeString_wooden(mMobile_wooden);
        return mMobile_wooden;
    }

    public String getHideMobile_wooden() {
        return StringUtil_wooden.bankAccountHideFront_wooden(getMobile_wooden());
    }

    @SuppressLint("ApplySharedPref")
    public void setMobile_wooden(String mobile) {
        this.mMobile_wooden = StringUtil_wooden.getSafeString_wooden(mobile);
        mSharedPreferences_wooden.edit().putString(SP_KEY_MOBILE_wooden, this.mMobile_wooden).commit();
    }

    public String getToken_wooden() {
        mToken_wooden = StringUtil_wooden.getSafeString_wooden(mToken_wooden);
        return mToken_wooden;
    }

    public String getCountryWord_wooden() {
        mCountryWord_wooden = StringUtil_wooden.getSafeString_wooden(mCountryWord_wooden);
        return mCountryWord_wooden;
    }

    public String getCountryName_wooden() {
        mCountryName_wooden = StringUtil_wooden.getSafeString_wooden(mCountryName_wooden);
        return mCountryName_wooden;
    }

    public String getUserId_wooden() {
        mUserId_wooden = StringUtil_wooden.getSafeString_wooden(mUserId_wooden);
        return mUserId_wooden;
    }

    @SuppressLint("ApplySharedPref")
    public void setToken_wooden(String token) {
        this.mToken_wooden = StringUtil_wooden.getSafeString_wooden(token);
        mSharedPreferences_wooden.edit().putString(SP_KEY_TOKEN_wooden, this.mToken_wooden).commit();
    }

    @SuppressLint("ApplySharedPref")
    public void setUserId_wooden(String userId) {
        this.mUserId_wooden = StringUtil_wooden.getSafeString_wooden(userId);
        mSharedPreferences_wooden.edit().putString(SP_KEY_USERID_wooden, this.mUserId_wooden).commit();
    }

    @SuppressLint("ApplySharedPref")
    public void setCountryWord_wooden(String countryWord) {
        this.mCountryWord_wooden = StringUtil_wooden.getSafeString_wooden(countryWord);
        mSharedPreferences_wooden.edit().putString(SP_KEY_COUNTRY_WORD_wooden, this.mCountryWord_wooden).commit();
    }

    @SuppressLint("ApplySharedPref")
    public void setCountryName_wooden(String countryName) {
        this.mCountryName_wooden = StringUtil_wooden.getSafeString_wooden(countryName);
        mSharedPreferences_wooden.edit().putString(SP_KEY_COUNTRY_NAME_wooden, this.mCountryName_wooden).commit();
    }


    public int getNormaldialogCount() {
        return normaldialogCount;
    }

    public int getActivedialogCount() {
        return activedialogCount;
    }


    @SuppressLint("ApplySharedPref")
    public void addNormaldialogCount(){
        normaldialogCount++;
        mSharedPreferences_wooden.edit().putInt(SP_KEY_NORMALDIALOG_COUNT_wooden,normaldialogCount).commit();
    }

    @SuppressLint("ApplySharedPref")
    public void addActivedialogCount(){
        activedialogCount++;
        mSharedPreferences_wooden.edit().putInt(SP_KEY_ACTIVEDIALOG_COUNT_wooden,activedialogCount).commit();
    }

}
